Skip to content

Implemented spawn config validation#40

Open
victormlg wants to merge 1 commit intocfengine:mainfrom
victormlg:spawn-validation
Open

Implemented spawn config validation#40
victormlg wants to merge 1 commit intocfengine:mainfrom
victormlg:spawn-validation

Conversation

@victormlg
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

@olehermanse olehermanse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit hard to follow the code without seeing the bigger picture, please add:

  • --validate option which validates the config and won't spawn in the future when that is implemented.
  • Some shell tests which use the --validate option and prove that it's passing and failing in the right situations.
  • Some explanation and examples for the feature in the README. Clearly mark it as work in progress.

README.md Outdated
```yaml
templates:
ubuntu:
count: 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count should be moved to group, not be in template

Copy link
Copy Markdown
Contributor Author

@victormlg victormlg Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Templates is not a real key in the final config, all the names defined in templates get expanded before analyzing the config. Ex:

templates:
  mycfengine: 
    version: 3.27.0

groups:
  - myhub:
      role: hub
      cfengine: mycfengine

Gets turned into:

groups:
  - myhub:
      role: hub
      cfengine: 
        version: 3.27.0

Also, I believe it makes sense to have "count" inside "spawn", Ex:

groups:
 - client1:
      role: client
      source:
        count: 4
        mode: spawn
        spawn:
          provider: vagrant
          vagrant:
            box: ubuntu/focal64
 
  - client2:
      role: client
      source:
        # count: 4. Here count doesn't make sense, because we have saved hosts
        mode: save
        hosts: [ 8.8.8.8 ]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but:

  1. You say that templates are not "real" keys, but I still think we should show examples that make sense to us and are useful for users. Thus, can you adjust the example to where you use a template to specify the provider and and box name, but you don't specify count inside the template, instead the normal case would be to specify this in the group.
  2. In your first example there, what decides that mycfengine should be expanded as a template? Is it just based on the fact that the string happens to be matching the name of a template?
  3. I agree that it doesn't make sense to include count there when you have hosts. count should always be the length of hosts in that case.

Copy link
Copy Markdown
Contributor Author

@victormlg victormlg Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your first example there, what decides that mycfengine should be expanded as a template? Is it just based on the fact that the string happens to be matching the name of a template?

Yes, exactly. We iterate through all the defined groups, and check if values match with one of the defined template name. If they do match, the value is replaced with the template

return self


def rgetattr(obj, attr, *args):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused function?

Copy link
Copy Markdown
Contributor Author

@victormlg victormlg Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not used for now but it will be used later. It's a getattr that doesn't throw an exception if one of the keys is missing. Ex: rgetattr(obj, "source.spawn.provider")

Signed-off-by: Victor Moene <victor.moene@northern.tech>
@victormlg victormlg requested a review from larsewi April 10, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants